/**
 *  *2010-7-11 上午01:34:11  add 
 */
package com.base.myproject.client.busi.business;

import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.tools.BaseRatify;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * 提交审批对话框
 * 	RatifyInfo ratifyinfo = new RatifyInfo();
			ratifyinfo.setBusi("1002");
			ratifyinfo.setIcode("00002");
			ratifyinfo.setFlowname("simple1");
			BaseRatifyDialogX bdx = new BaseRatifyDialogX(ratifyinfo);
			bdx.show();
 * @author Administrator
 *2010-7-11
 * javazgw@gmail.com
 */
public class BaseRatifyDialogX {
	Dialog d = new Dialog();
	RatifyInfo ratifyinfo = new RatifyInfo();
	com.extjs.gxt.ui.client.widget.FramePanel ratify_flow = com.extjs.gxt.ui.client.widget.FramePanel
	.pop();
	public BaseRatifyDialogX(RatifyInfo ratifyinfo )
	{
		this.ratifyinfo= ratifyinfo;
		init();
	}

	private void init() {
		initWidgetx();
		
	}

	private void initWidgetx() {
		d.setSize(393, 499);
		d.setHeading("提交审批");
		d.setButtons(Dialog.OKCANCEL);
		d.getButtonById(Dialog.OK).setText("提交");
		d.getButtonById(Dialog.CANCEL).setText("取消");
		VerticalPanel cp = new VerticalPanel();
		cp.add(ratify_flow);
		d.add(cp);
		d.getButtonById(Dialog.OK).addListener(Events.Select , getListener());
		d.getButtonById(Dialog.CANCEL).addListener(Events.Select , getListener());
	}
	void load() {
		ratify_flow.el().setElementAttribute("src", "./busijsp/ratify/getratifyimage.jsp?busicode="+ratifyinfo.getBusi());
		ratify_flow.el().setElementAttribute("height", "378px");
		ratify_flow.el().setElementAttribute("width", "370px");
		
		
//		com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
//				.create(com.base.myproject.client.tools.GreetingService.class);
//		greetingService.getDataSet("select 'aa' as danju ,'我' as bcode ", getAsyncCallback());

	}
/*
	private AsyncCallback<DataSet> getAsyncCallback() {

		AsyncCallback<DataSet> callback = new AsyncCallback<DataSet>() {

			@Override
			public void onFailure(Throwable caught) {

			}

			@Override
			public void onSuccess(DataSet result) {
				if(result.getRowCount()>0)
				{
				
				ratify_flow.el().setElementAttribute("src", "./busijsp/ratify/getratifyimage.jsp?busicode="+ratifyinfo.getBusi());
				ratify_flow.el().setElementAttribute("height", "378px");
				ratify_flow.el().setElementAttribute("width", "370px");
				
				
				
				}
				else
				{
					
				}
			}

		};
		return callback;
	}*/
	
	public void show()
	{
		
		d.show();
		load();
	}

	void close()
	{
		d.hide();
	}
	int sync = 0;                                                      
	Listener<BaseEvent> defaultlistener;                               
                                                                     
	Listener<BaseEvent> getListener() {                                
		if(defaultlistener!=null)                                        
		{                                                                
			return defaultlistener;                                        
		}                                                                
                                                                     
		defaultlistener = new Listener<BaseEvent>() {                    
			public void handleEvent(BaseEvent be) {                        
				sync++;                                                      
				try {                                                        
					if (sync == 1) {                                           
						if (be.getType() == Events.Select) {                     
							if (be.getSource().equals(d.getButtonById(Dialog.OK))) {                            
								BaseRatify.getInstance().doratify(ratifyinfo.getBusi(),ratifyinfo.getIcode(),ratifyinfo.getFlowname()) ;                           
							}  
							else if (be.getSource().equals(d.getButtonById(Dialog.CANCEL))) {                            
                                close();
							}  
						} else if (be.getType() == Events.Change) {              
							if (be.getSource().equals("")) {         
                                                                     
							}                                                      
						} else if (be.getType() == Events.KeyUp) {               
							if (be instanceof ComponentEvent) {                    
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{                                                    
								}                                                    
							}                                                      
						}                                                        
					}                                                          
				} finally {                                                  
					sync--;                                                    
				}                                                            
			}                                                              
                                                                     
		};                                                               
		return defaultlistener;                                          
	}                                                                  

}
